<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>自定义事件</title> 
        <script src = "../../vue.min.js"></script>
    </head>
    <body>
    <!-- 注意：该示例需使用Vue.js 1.x的版本 -->
        <div id = "app">
            {{message}}
            <component-a></component-a>
        </div>
        <script>
            var bus = new Vue();

            Vue.component('component-a',{
                template:'<button @click="handleEvent">传递事件</button>',
                methods:{
                    handleEvent:function() {
                        //mark 点击按钮会通过bus把时间on-message发出去
                        bus.$emit('on-message','来自组件component-a的内容')
                    }
                }
            });
            var app = new Vue({
                el: '#app',
                data:{
                    message:''
                },
                mounted:function(){
                    var _this=this;
                    //mark 在实例初始化时，监听来自bus实例的事件
                    bus.$on('on-message',function (msg) {
                        _this.message=msg;
                    })
                }
            })
        </script>
    </body>
</html>